<?xml version='1.0' encoding='UTF-8' ?>
<f:view xmlns="http://www.w3.org/1999/xhtml" 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pm="http://primefaces.org/mobile"
        contentType="text/html">
    
    <pm:page title="MyTV" >
        <f:facet name="postinit">
            <script type="text/javascript">
                jQuery(document).ready(function(){
                    //Home Page icon
                    //jQuery('head').append('<link rel="apple-touch-icon" href="images/logo.jpg"/>');
                    //Splash screen for iPhone
                    //jQuery('head').append('<link rel="apple-touch-startup-image" href="resources/mail.png"/>');
                    //This will hide the browser address bar
                    jQuery('head').append('<meta name="apple-mobile-web-app-capable" content="yes" />');
                    jQuery('head').append('<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"/>');
                    //Adds a custom style sheet
                    jQuery('head').append('<link href="resources/style.css" rel="stylesheet" type="text/css"/>');
                    jQuery('head').append('<link rel="icon" href="resources/images/mytv.ico" />');
                });
            </script>
        </f:facet>
        
        <pm:view id="mainView">
            <pm:header title="MyTV" />
            <pm:content>
                <h:form id="formMain">
                    <h:panelGroup rendered="#{not sessionBean.logged}">
                        <h:outputLabel for="nickName" value="#{lang.user}"/>
                        <h:inputText id="nickName" value="#{indexBean.nickName}" />
                        <p:watermark for="nickName" value="#{lang.user}"/>

                        <h:outputLabel for="password" value="#{lang.password}"/>
                        <h:inputSecret id="password" value="#{indexBean.password}" />
                        <p:watermark for="password" value="#{lang.password}"/>

                        <p:separator />
                        <h:outputText value="#{lang.loginError}" rendered="#{indexBean.errorLogin}" style="color: red;font-weight: bold;"/>
                        <p:separator rendered="#{indexBean.errorLogin}"/>

                        <pm:buttonGroup orientation="horizontal">
                            <p:button value="#{lang.register}" icon="add" href="#register?transition=flip"/>
                            <p:commandButton value="#{lang.login}" icon="user" update="@form" actionListener="#{indexBean.login}"/>
                        </pm:buttonGroup>
                    </h:panelGroup>
                    <h:panelGroup rendered="#{sessionBean.logged and sessionBean.pathNull}">
                        <h:panelGroup>
                            <h:outputLabel for="rgCode" value=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        "#{lang.code}" style="font-weight: bold"/><br/>
                            <h:outputText id="rgCode" value="#{sessionBean.user.code}"/><br/>
                            <br/>
                            <h:outputLabel for="rgNickName" value="#{lang.user}" style="font-weight: bold"/><br/>
                            <h:outputText id="rgNickName" value="#{sessionBean.user.nickname}"/>
                        </h:panelGroup>
                        <p:separator />
                        <p:dataList value="#{indexBean.categories}" var="c" type="inset">
                            <p:column>
                                <p:commandLink value="#{c}" update="@form">
                                    <f:setPropertyActionListener value="#{c}" target="#{sessionBean.path}" />
                                </p:commandLink>
                            </p:column>
                        </p:dataList>
                        <p:separator />
                        <pm:buttonGroup>
                            <p:button value="#{lang.config}" icon="gear" href="#{configBean.rootPath}/config.xhtml"/>
                        </pm:buttonGroup>
                        <p:separator />
                        <br/>
                        <p:separator />
                        <p:commandButton value="#{lang.logout}" icon="back" update="@form" actionListener="#{sessionBean.disconnect}"/>
                    </h:panelGroup>
                    <h:panelGroup rendered="#{sessionBean.logged and sessionBean.directory}">
                        <h:outputText value="#{sessionBean.path}" style="font-weight: bolder;"/>
                        <p:commandButton value="#{lang.back}" update="@form">
                            <f:setPropertyActionListener value=".." target="#{sessionBean.path}" />
                        </p:commandButton>
                        <p:separator/>
                        <p:dataList value="#{indexBean.childs}" var="i" type="inset">
                            <p:column>
                                <p:commandLink value="#{i}" update="@form">
                                    <f:setPropertyActionListener value="#{i}" target="#{sessionBean.path}" />
                                </p:commandLink>
                            </p:column>
                        </p:dataList>
                        <p:separator/>
                        <p:commandButton value="#{lang.back}" update="@form">
                            <f:setPropertyActionListener value=".." target="#{sessionBean.path}" />
                        </p:commandButton>
                    </h:panelGroup>
                    <h:panelGroup rendered="#{sessionBean.logged and sessionBean.file}">
                        <h:outputText value="#{sessionBean.path}" style="font-weight: bolder;"/>
                        <p:separator/>
                        <h:panelGrid columns="3">
                            <p:commandButton icon="play" value="Pl" actionListener="#{indexBean.play}"/>
                            <p:commandButton icon="pause" value="Pa" actionListener="#{indexBean.pause}"/>
                            <p:commandButton icon="stop" value="St" actionListener="#{indexBean.stop}"/>
                            <p:commandButton icon="vol-minus" value="V-" actionListener="#{indexBean.volMin}"/>
                            <h:panelGroup/>
                            <p:commandButton icon="vol-plus" value="V+" actionListener="#{indexBean.volPlus}"/>
                            <h:panelGroup/>
                            <p:commandButton icon="screen" value="A" actionListener="#{indexBean.screen}"/>
                            <h:panelGroup/>
                            <p:commandButton icon="backward" value="#{lang.backward}" actionListener="#{indexBean.backward}"/>
                            <h:panelGroup/>
                            <p:commandButton icon="fordward" value="#{lang.fordward}" actionListener="#{indexBean.fordward}"/>
                        </h:panelGrid>
                        <p:separator/>
                        <p:commandButton value="#{lang.back}" update="@form">
                            <f:setPropertyActionListener value=".." target="#{sessionBean.path}" />
                        </p:commandButton>
                    </h:panelGroup>
                </h:form>
            </pm:content>
        </pm:view>

        <pm:view id="register">
            <pm:header title="MyTV">
                <f:facet name="left">
                    <p:button value="#{lang.back}" icon="back" href="#mainView?transition=flip"/>
                </f:facet>
            </pm:header>
            <pm:content>
                <h:form>
                    <h:panelGroup rendered="#{not sessionBean.logged}">
                        <h:outputLabel for="rgNickName" value="#{lang.user}"/>
                        <h:inputText id="rgNickName" value="#{registerUserBean.user.nickname}" />
                        <p:watermark for="rgNickName" value="#{lang.user}"/>
                        
                        <h:outputLabel for="rgPassword" value="#{lang.password}"/>
                        <h:inputSecret id="rgPassword" value="#{registerUserBean.user.password}" />
                        <p:watermark for="rgPassword" value="#{lang.password}"/>
                        
                        <h:outputLabel for="rgPasswordConfirm" value="#{lang.password}"/>
                        <h:inputSecret id="rgPasswordConfirm" value="#{registerUserBean.confirmPassword}" />
                        <p:watermark for="rgPasswordConfirm" value="#{lang.passwordConfirm}"/>
                        
                        <p:separator />
                        <h:outputText value="#{lang.registerError}" rendered="#{registerUserBean.errorRegister}" style="color: red;font-weight: bold;"/>
                        <h:outputText value="#{lang.diferentPassword}" rendered="#{not registerUserBean.samePassword}" style="color: red;font-weight: bold;"/>
                        <h:outputText value="#{lang.userExist}" rendered="#{registerUserBean.existUser}" style="color: red;font-weight: bold;"/>
                        <p:separator rendered="#{registerUserBean.errorRegister or not registerUserBean.samePassword or registerUserBean.existUser}"/>
                        <p:commandButton value="#{lang.register}" icon="user" update="@form :formMain" actionListener="#{registerUserBean.register}"/>
                    </h:panelGroup>
                    <h:panelGroup rendered="#{sessionBean.logged}">
                        <h:outputText value="#{lang.thanksForRegister}"/>
                    </h:panelGroup>
                </h:form>
            </pm:content>
        </pm:view>
        
    </pm:page>
</f:view>